package com.xjgzinfo.usdp.web.rest;

import com.xjgzinfo.usdp.AvueServer4jApp;
import com.xjgzinfo.usdp.config.TestSecurityConfiguration;
import com.xjgzinfo.usdp.domain.TemplateType;
import com.xjgzinfo.usdp.repository.TemplateTypeRepository;
import com.xjgzinfo.usdp.service.TemplateTypeService;
import com.xjgzinfo.usdp.service.dto.TemplateTypeDTO;
import com.xjgzinfo.usdp.service.mapper.TemplateTypeMapper;
import com.xjgzinfo.usdp.service.dto.TemplateTypeCriteria;
import com.xjgzinfo.usdp.service.TemplateTypeQueryService;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

/**
 * Integration tests for the {@link TemplateTypeResource} REST controller.
 */
@SpringBootTest(classes = { AvueServer4jApp.class, TestSecurityConfiguration.class })
@AutoConfigureMockMvc
@WithMockUser
public class TemplateTypeResourceIT {

    private static final String DEFAULT_NAME = "AAAAAAAAAA";
    private static final String UPDATED_NAME = "BBBBBBBBBB";

    private static final Long DEFAULT_PID = 1L;
    private static final Long UPDATED_PID = 2L;
    private static final Long SMALLER_PID = 1L - 1L;

    private static final String DEFAULT_CODE = "AAAAAAAAAA";
    private static final String UPDATED_CODE = "BBBBBBBBBB";

    private static final Long DEFAULT_RID = 1L;
    private static final Long UPDATED_RID = 2L;
    private static final Long SMALLER_RID = 1L - 1L;

    private static final Boolean DEFAULT_ENABLED = false;
    private static final Boolean UPDATED_ENABLED = true;

    private static final Integer DEFAULT_LEVEL = 1;
    private static final Integer UPDATED_LEVEL = 2;
    private static final Integer SMALLER_LEVEL = 1 - 1;

    @Autowired
    private TemplateTypeRepository templateTypeRepository;

    @Autowired
    private TemplateTypeMapper templateTypeMapper;

    @Autowired
    private TemplateTypeService templateTypeService;

    @Autowired
    private TemplateTypeQueryService templateTypeQueryService;

    @Autowired
    private EntityManager em;

    @Autowired
    private MockMvc restTemplateTypeMockMvc;

    private TemplateType templateType;

    /**
     * Create an entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static TemplateType createEntity(EntityManager em) {
        TemplateType templateType = new TemplateType()
            .name(DEFAULT_NAME)
            .pid(DEFAULT_PID)
            .code(DEFAULT_CODE)
            .rid(DEFAULT_RID)
            .enabled(DEFAULT_ENABLED)
            .level(DEFAULT_LEVEL);
        return templateType;
    }
    /**
     * Create an updated entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static TemplateType createUpdatedEntity(EntityManager em) {
        TemplateType templateType = new TemplateType()
            .name(UPDATED_NAME)
            .pid(UPDATED_PID)
            .code(UPDATED_CODE)
            .rid(UPDATED_RID)
            .enabled(UPDATED_ENABLED)
            .level(UPDATED_LEVEL);
        return templateType;
    }

    @BeforeEach
    public void initTest() {
        templateType = createEntity(em);
    }

    @Test
    @Transactional
    public void createTemplateType() throws Exception {
        int databaseSizeBeforeCreate = templateTypeRepository.findAll().size();
        // Create the TemplateType
        TemplateTypeDTO templateTypeDTO = templateTypeMapper.toDto(templateType);
        restTemplateTypeMockMvc.perform(post("/api/template-types").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(templateTypeDTO)))
            .andExpect(status().isCreated());

        // Validate the TemplateType in the database
        List<TemplateType> templateTypeList = templateTypeRepository.findAll();
        assertThat(templateTypeList).hasSize(databaseSizeBeforeCreate + 1);
        TemplateType testTemplateType = templateTypeList.get(templateTypeList.size() - 1);
        assertThat(testTemplateType.getName()).isEqualTo(DEFAULT_NAME);
        assertThat(testTemplateType.getPid()).isEqualTo(DEFAULT_PID);
        assertThat(testTemplateType.getCode()).isEqualTo(DEFAULT_CODE);
        assertThat(testTemplateType.getRid()).isEqualTo(DEFAULT_RID);
        assertThat(testTemplateType.isEnabled()).isEqualTo(DEFAULT_ENABLED);
        assertThat(testTemplateType.getLevel()).isEqualTo(DEFAULT_LEVEL);
    }

    @Test
    @Transactional
    public void createTemplateTypeWithExistingId() throws Exception {
        int databaseSizeBeforeCreate = templateTypeRepository.findAll().size();

        // Create the TemplateType with an existing ID
        templateType.setId(1L);
        TemplateTypeDTO templateTypeDTO = templateTypeMapper.toDto(templateType);

        // An entity with an existing ID cannot be created, so this API call must fail
        restTemplateTypeMockMvc.perform(post("/api/template-types").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(templateTypeDTO)))
            .andExpect(status().isBadRequest());

        // Validate the TemplateType in the database
        List<TemplateType> templateTypeList = templateTypeRepository.findAll();
        assertThat(templateTypeList).hasSize(databaseSizeBeforeCreate);
    }


    @Test
    @Transactional
    public void checkNameIsRequired() throws Exception {
        int databaseSizeBeforeTest = templateTypeRepository.findAll().size();
        // set the field null
        templateType.setName(null);

        // Create the TemplateType, which fails.
        TemplateTypeDTO templateTypeDTO = templateTypeMapper.toDto(templateType);


        restTemplateTypeMockMvc.perform(post("/api/template-types").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(templateTypeDTO)))
            .andExpect(status().isBadRequest());

        List<TemplateType> templateTypeList = templateTypeRepository.findAll();
        assertThat(templateTypeList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkPidIsRequired() throws Exception {
        int databaseSizeBeforeTest = templateTypeRepository.findAll().size();
        // set the field null
        templateType.setPid(null);

        // Create the TemplateType, which fails.
        TemplateTypeDTO templateTypeDTO = templateTypeMapper.toDto(templateType);


        restTemplateTypeMockMvc.perform(post("/api/template-types").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(templateTypeDTO)))
            .andExpect(status().isBadRequest());

        List<TemplateType> templateTypeList = templateTypeRepository.findAll();
        assertThat(templateTypeList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkCodeIsRequired() throws Exception {
        int databaseSizeBeforeTest = templateTypeRepository.findAll().size();
        // set the field null
        templateType.setCode(null);

        // Create the TemplateType, which fails.
        TemplateTypeDTO templateTypeDTO = templateTypeMapper.toDto(templateType);


        restTemplateTypeMockMvc.perform(post("/api/template-types").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(templateTypeDTO)))
            .andExpect(status().isBadRequest());

        List<TemplateType> templateTypeList = templateTypeRepository.findAll();
        assertThat(templateTypeList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkRidIsRequired() throws Exception {
        int databaseSizeBeforeTest = templateTypeRepository.findAll().size();
        // set the field null
        templateType.setRid(null);

        // Create the TemplateType, which fails.
        TemplateTypeDTO templateTypeDTO = templateTypeMapper.toDto(templateType);


        restTemplateTypeMockMvc.perform(post("/api/template-types").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(templateTypeDTO)))
            .andExpect(status().isBadRequest());

        List<TemplateType> templateTypeList = templateTypeRepository.findAll();
        assertThat(templateTypeList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkEnabledIsRequired() throws Exception {
        int databaseSizeBeforeTest = templateTypeRepository.findAll().size();
        // set the field null
        templateType.setEnabled(null);

        // Create the TemplateType, which fails.
        TemplateTypeDTO templateTypeDTO = templateTypeMapper.toDto(templateType);


        restTemplateTypeMockMvc.perform(post("/api/template-types").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(templateTypeDTO)))
            .andExpect(status().isBadRequest());

        List<TemplateType> templateTypeList = templateTypeRepository.findAll();
        assertThat(templateTypeList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkLevelIsRequired() throws Exception {
        int databaseSizeBeforeTest = templateTypeRepository.findAll().size();
        // set the field null
        templateType.setLevel(null);

        // Create the TemplateType, which fails.
        TemplateTypeDTO templateTypeDTO = templateTypeMapper.toDto(templateType);


        restTemplateTypeMockMvc.perform(post("/api/template-types").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(templateTypeDTO)))
            .andExpect(status().isBadRequest());

        List<TemplateType> templateTypeList = templateTypeRepository.findAll();
        assertThat(templateTypeList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void getAllTemplateTypes() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList
        restTemplateTypeMockMvc.perform(get("/api/template-types?sort=id,desc"))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(templateType.getId().intValue())))
            .andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME)))
            .andExpect(jsonPath("$.[*].pid").value(hasItem(DEFAULT_PID.intValue())))
            .andExpect(jsonPath("$.[*].code").value(hasItem(DEFAULT_CODE)))
            .andExpect(jsonPath("$.[*].rid").value(hasItem(DEFAULT_RID.intValue())))
            .andExpect(jsonPath("$.[*].enabled").value(hasItem(DEFAULT_ENABLED.booleanValue())))
            .andExpect(jsonPath("$.[*].level").value(hasItem(DEFAULT_LEVEL)));
    }
    
    @Test
    @Transactional
    public void getTemplateType() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get the templateType
        restTemplateTypeMockMvc.perform(get("/api/template-types/{id}", templateType.getId()))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.id").value(templateType.getId().intValue()))
            .andExpect(jsonPath("$.name").value(DEFAULT_NAME))
            .andExpect(jsonPath("$.pid").value(DEFAULT_PID.intValue()))
            .andExpect(jsonPath("$.code").value(DEFAULT_CODE))
            .andExpect(jsonPath("$.rid").value(DEFAULT_RID.intValue()))
            .andExpect(jsonPath("$.enabled").value(DEFAULT_ENABLED.booleanValue()))
            .andExpect(jsonPath("$.level").value(DEFAULT_LEVEL));
    }


    @Test
    @Transactional
    public void getTemplateTypesByIdFiltering() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        Long id = templateType.getId();

        defaultTemplateTypeShouldBeFound("id.equals=" + id);
        defaultTemplateTypeShouldNotBeFound("id.notEquals=" + id);

        defaultTemplateTypeShouldBeFound("id.greaterThanOrEqual=" + id);
        defaultTemplateTypeShouldNotBeFound("id.greaterThan=" + id);

        defaultTemplateTypeShouldBeFound("id.lessThanOrEqual=" + id);
        defaultTemplateTypeShouldNotBeFound("id.lessThan=" + id);
    }


    @Test
    @Transactional
    public void getAllTemplateTypesByNameIsEqualToSomething() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where name equals to DEFAULT_NAME
        defaultTemplateTypeShouldBeFound("name.equals=" + DEFAULT_NAME);

        // Get all the templateTypeList where name equals to UPDATED_NAME
        defaultTemplateTypeShouldNotBeFound("name.equals=" + UPDATED_NAME);
    }

    @Test
    @Transactional
    public void getAllTemplateTypesByNameIsNotEqualToSomething() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where name not equals to DEFAULT_NAME
        defaultTemplateTypeShouldNotBeFound("name.notEquals=" + DEFAULT_NAME);

        // Get all the templateTypeList where name not equals to UPDATED_NAME
        defaultTemplateTypeShouldBeFound("name.notEquals=" + UPDATED_NAME);
    }

    @Test
    @Transactional
    public void getAllTemplateTypesByNameIsInShouldWork() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where name in DEFAULT_NAME or UPDATED_NAME
        defaultTemplateTypeShouldBeFound("name.in=" + DEFAULT_NAME + "," + UPDATED_NAME);

        // Get all the templateTypeList where name equals to UPDATED_NAME
        defaultTemplateTypeShouldNotBeFound("name.in=" + UPDATED_NAME);
    }

    @Test
    @Transactional
    public void getAllTemplateTypesByNameIsNullOrNotNull() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where name is not null
        defaultTemplateTypeShouldBeFound("name.specified=true");

        // Get all the templateTypeList where name is null
        defaultTemplateTypeShouldNotBeFound("name.specified=false");
    }
                @Test
    @Transactional
    public void getAllTemplateTypesByNameContainsSomething() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where name contains DEFAULT_NAME
        defaultTemplateTypeShouldBeFound("name.contains=" + DEFAULT_NAME);

        // Get all the templateTypeList where name contains UPDATED_NAME
        defaultTemplateTypeShouldNotBeFound("name.contains=" + UPDATED_NAME);
    }

    @Test
    @Transactional
    public void getAllTemplateTypesByNameNotContainsSomething() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where name does not contain DEFAULT_NAME
        defaultTemplateTypeShouldNotBeFound("name.doesNotContain=" + DEFAULT_NAME);

        // Get all the templateTypeList where name does not contain UPDATED_NAME
        defaultTemplateTypeShouldBeFound("name.doesNotContain=" + UPDATED_NAME);
    }


    @Test
    @Transactional
    public void getAllTemplateTypesByPidIsEqualToSomething() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where pid equals to DEFAULT_PID
        defaultTemplateTypeShouldBeFound("pid.equals=" + DEFAULT_PID);

        // Get all the templateTypeList where pid equals to UPDATED_PID
        defaultTemplateTypeShouldNotBeFound("pid.equals=" + UPDATED_PID);
    }

    @Test
    @Transactional
    public void getAllTemplateTypesByPidIsNotEqualToSomething() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where pid not equals to DEFAULT_PID
        defaultTemplateTypeShouldNotBeFound("pid.notEquals=" + DEFAULT_PID);

        // Get all the templateTypeList where pid not equals to UPDATED_PID
        defaultTemplateTypeShouldBeFound("pid.notEquals=" + UPDATED_PID);
    }

    @Test
    @Transactional
    public void getAllTemplateTypesByPidIsInShouldWork() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where pid in DEFAULT_PID or UPDATED_PID
        defaultTemplateTypeShouldBeFound("pid.in=" + DEFAULT_PID + "," + UPDATED_PID);

        // Get all the templateTypeList where pid equals to UPDATED_PID
        defaultTemplateTypeShouldNotBeFound("pid.in=" + UPDATED_PID);
    }

    @Test
    @Transactional
    public void getAllTemplateTypesByPidIsNullOrNotNull() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where pid is not null
        defaultTemplateTypeShouldBeFound("pid.specified=true");

        // Get all the templateTypeList where pid is null
        defaultTemplateTypeShouldNotBeFound("pid.specified=false");
    }

    @Test
    @Transactional
    public void getAllTemplateTypesByPidIsGreaterThanOrEqualToSomething() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where pid is greater than or equal to DEFAULT_PID
        defaultTemplateTypeShouldBeFound("pid.greaterThanOrEqual=" + DEFAULT_PID);

        // Get all the templateTypeList where pid is greater than or equal to UPDATED_PID
        defaultTemplateTypeShouldNotBeFound("pid.greaterThanOrEqual=" + UPDATED_PID);
    }

    @Test
    @Transactional
    public void getAllTemplateTypesByPidIsLessThanOrEqualToSomething() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where pid is less than or equal to DEFAULT_PID
        defaultTemplateTypeShouldBeFound("pid.lessThanOrEqual=" + DEFAULT_PID);

        // Get all the templateTypeList where pid is less than or equal to SMALLER_PID
        defaultTemplateTypeShouldNotBeFound("pid.lessThanOrEqual=" + SMALLER_PID);
    }

    @Test
    @Transactional
    public void getAllTemplateTypesByPidIsLessThanSomething() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where pid is less than DEFAULT_PID
        defaultTemplateTypeShouldNotBeFound("pid.lessThan=" + DEFAULT_PID);

        // Get all the templateTypeList where pid is less than UPDATED_PID
        defaultTemplateTypeShouldBeFound("pid.lessThan=" + UPDATED_PID);
    }

    @Test
    @Transactional
    public void getAllTemplateTypesByPidIsGreaterThanSomething() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where pid is greater than DEFAULT_PID
        defaultTemplateTypeShouldNotBeFound("pid.greaterThan=" + DEFAULT_PID);

        // Get all the templateTypeList where pid is greater than SMALLER_PID
        defaultTemplateTypeShouldBeFound("pid.greaterThan=" + SMALLER_PID);
    }


    @Test
    @Transactional
    public void getAllTemplateTypesByCodeIsEqualToSomething() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where code equals to DEFAULT_CODE
        defaultTemplateTypeShouldBeFound("code.equals=" + DEFAULT_CODE);

        // Get all the templateTypeList where code equals to UPDATED_CODE
        defaultTemplateTypeShouldNotBeFound("code.equals=" + UPDATED_CODE);
    }

    @Test
    @Transactional
    public void getAllTemplateTypesByCodeIsNotEqualToSomething() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where code not equals to DEFAULT_CODE
        defaultTemplateTypeShouldNotBeFound("code.notEquals=" + DEFAULT_CODE);

        // Get all the templateTypeList where code not equals to UPDATED_CODE
        defaultTemplateTypeShouldBeFound("code.notEquals=" + UPDATED_CODE);
    }

    @Test
    @Transactional
    public void getAllTemplateTypesByCodeIsInShouldWork() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where code in DEFAULT_CODE or UPDATED_CODE
        defaultTemplateTypeShouldBeFound("code.in=" + DEFAULT_CODE + "," + UPDATED_CODE);

        // Get all the templateTypeList where code equals to UPDATED_CODE
        defaultTemplateTypeShouldNotBeFound("code.in=" + UPDATED_CODE);
    }

    @Test
    @Transactional
    public void getAllTemplateTypesByCodeIsNullOrNotNull() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where code is not null
        defaultTemplateTypeShouldBeFound("code.specified=true");

        // Get all the templateTypeList where code is null
        defaultTemplateTypeShouldNotBeFound("code.specified=false");
    }
                @Test
    @Transactional
    public void getAllTemplateTypesByCodeContainsSomething() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where code contains DEFAULT_CODE
        defaultTemplateTypeShouldBeFound("code.contains=" + DEFAULT_CODE);

        // Get all the templateTypeList where code contains UPDATED_CODE
        defaultTemplateTypeShouldNotBeFound("code.contains=" + UPDATED_CODE);
    }

    @Test
    @Transactional
    public void getAllTemplateTypesByCodeNotContainsSomething() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where code does not contain DEFAULT_CODE
        defaultTemplateTypeShouldNotBeFound("code.doesNotContain=" + DEFAULT_CODE);

        // Get all the templateTypeList where code does not contain UPDATED_CODE
        defaultTemplateTypeShouldBeFound("code.doesNotContain=" + UPDATED_CODE);
    }


    @Test
    @Transactional
    public void getAllTemplateTypesByRidIsEqualToSomething() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where rid equals to DEFAULT_RID
        defaultTemplateTypeShouldBeFound("rid.equals=" + DEFAULT_RID);

        // Get all the templateTypeList where rid equals to UPDATED_RID
        defaultTemplateTypeShouldNotBeFound("rid.equals=" + UPDATED_RID);
    }

    @Test
    @Transactional
    public void getAllTemplateTypesByRidIsNotEqualToSomething() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where rid not equals to DEFAULT_RID
        defaultTemplateTypeShouldNotBeFound("rid.notEquals=" + DEFAULT_RID);

        // Get all the templateTypeList where rid not equals to UPDATED_RID
        defaultTemplateTypeShouldBeFound("rid.notEquals=" + UPDATED_RID);
    }

    @Test
    @Transactional
    public void getAllTemplateTypesByRidIsInShouldWork() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where rid in DEFAULT_RID or UPDATED_RID
        defaultTemplateTypeShouldBeFound("rid.in=" + DEFAULT_RID + "," + UPDATED_RID);

        // Get all the templateTypeList where rid equals to UPDATED_RID
        defaultTemplateTypeShouldNotBeFound("rid.in=" + UPDATED_RID);
    }

    @Test
    @Transactional
    public void getAllTemplateTypesByRidIsNullOrNotNull() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where rid is not null
        defaultTemplateTypeShouldBeFound("rid.specified=true");

        // Get all the templateTypeList where rid is null
        defaultTemplateTypeShouldNotBeFound("rid.specified=false");
    }

    @Test
    @Transactional
    public void getAllTemplateTypesByRidIsGreaterThanOrEqualToSomething() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where rid is greater than or equal to DEFAULT_RID
        defaultTemplateTypeShouldBeFound("rid.greaterThanOrEqual=" + DEFAULT_RID);

        // Get all the templateTypeList where rid is greater than or equal to UPDATED_RID
        defaultTemplateTypeShouldNotBeFound("rid.greaterThanOrEqual=" + UPDATED_RID);
    }

    @Test
    @Transactional
    public void getAllTemplateTypesByRidIsLessThanOrEqualToSomething() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where rid is less than or equal to DEFAULT_RID
        defaultTemplateTypeShouldBeFound("rid.lessThanOrEqual=" + DEFAULT_RID);

        // Get all the templateTypeList where rid is less than or equal to SMALLER_RID
        defaultTemplateTypeShouldNotBeFound("rid.lessThanOrEqual=" + SMALLER_RID);
    }

    @Test
    @Transactional
    public void getAllTemplateTypesByRidIsLessThanSomething() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where rid is less than DEFAULT_RID
        defaultTemplateTypeShouldNotBeFound("rid.lessThan=" + DEFAULT_RID);

        // Get all the templateTypeList where rid is less than UPDATED_RID
        defaultTemplateTypeShouldBeFound("rid.lessThan=" + UPDATED_RID);
    }

    @Test
    @Transactional
    public void getAllTemplateTypesByRidIsGreaterThanSomething() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where rid is greater than DEFAULT_RID
        defaultTemplateTypeShouldNotBeFound("rid.greaterThan=" + DEFAULT_RID);

        // Get all the templateTypeList where rid is greater than SMALLER_RID
        defaultTemplateTypeShouldBeFound("rid.greaterThan=" + SMALLER_RID);
    }


    @Test
    @Transactional
    public void getAllTemplateTypesByEnabledIsEqualToSomething() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where enabled equals to DEFAULT_ENABLED
        defaultTemplateTypeShouldBeFound("enabled.equals=" + DEFAULT_ENABLED);

        // Get all the templateTypeList where enabled equals to UPDATED_ENABLED
        defaultTemplateTypeShouldNotBeFound("enabled.equals=" + UPDATED_ENABLED);
    }

    @Test
    @Transactional
    public void getAllTemplateTypesByEnabledIsNotEqualToSomething() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where enabled not equals to DEFAULT_ENABLED
        defaultTemplateTypeShouldNotBeFound("enabled.notEquals=" + DEFAULT_ENABLED);

        // Get all the templateTypeList where enabled not equals to UPDATED_ENABLED
        defaultTemplateTypeShouldBeFound("enabled.notEquals=" + UPDATED_ENABLED);
    }

    @Test
    @Transactional
    public void getAllTemplateTypesByEnabledIsInShouldWork() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where enabled in DEFAULT_ENABLED or UPDATED_ENABLED
        defaultTemplateTypeShouldBeFound("enabled.in=" + DEFAULT_ENABLED + "," + UPDATED_ENABLED);

        // Get all the templateTypeList where enabled equals to UPDATED_ENABLED
        defaultTemplateTypeShouldNotBeFound("enabled.in=" + UPDATED_ENABLED);
    }

    @Test
    @Transactional
    public void getAllTemplateTypesByEnabledIsNullOrNotNull() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where enabled is not null
        defaultTemplateTypeShouldBeFound("enabled.specified=true");

        // Get all the templateTypeList where enabled is null
        defaultTemplateTypeShouldNotBeFound("enabled.specified=false");
    }

    @Test
    @Transactional
    public void getAllTemplateTypesByLevelIsEqualToSomething() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where level equals to DEFAULT_LEVEL
        defaultTemplateTypeShouldBeFound("level.equals=" + DEFAULT_LEVEL);

        // Get all the templateTypeList where level equals to UPDATED_LEVEL
        defaultTemplateTypeShouldNotBeFound("level.equals=" + UPDATED_LEVEL);
    }

    @Test
    @Transactional
    public void getAllTemplateTypesByLevelIsNotEqualToSomething() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where level not equals to DEFAULT_LEVEL
        defaultTemplateTypeShouldNotBeFound("level.notEquals=" + DEFAULT_LEVEL);

        // Get all the templateTypeList where level not equals to UPDATED_LEVEL
        defaultTemplateTypeShouldBeFound("level.notEquals=" + UPDATED_LEVEL);
    }

    @Test
    @Transactional
    public void getAllTemplateTypesByLevelIsInShouldWork() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where level in DEFAULT_LEVEL or UPDATED_LEVEL
        defaultTemplateTypeShouldBeFound("level.in=" + DEFAULT_LEVEL + "," + UPDATED_LEVEL);

        // Get all the templateTypeList where level equals to UPDATED_LEVEL
        defaultTemplateTypeShouldNotBeFound("level.in=" + UPDATED_LEVEL);
    }

    @Test
    @Transactional
    public void getAllTemplateTypesByLevelIsNullOrNotNull() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where level is not null
        defaultTemplateTypeShouldBeFound("level.specified=true");

        // Get all the templateTypeList where level is null
        defaultTemplateTypeShouldNotBeFound("level.specified=false");
    }

    @Test
    @Transactional
    public void getAllTemplateTypesByLevelIsGreaterThanOrEqualToSomething() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where level is greater than or equal to DEFAULT_LEVEL
        defaultTemplateTypeShouldBeFound("level.greaterThanOrEqual=" + DEFAULT_LEVEL);

        // Get all the templateTypeList where level is greater than or equal to UPDATED_LEVEL
        defaultTemplateTypeShouldNotBeFound("level.greaterThanOrEqual=" + UPDATED_LEVEL);
    }

    @Test
    @Transactional
    public void getAllTemplateTypesByLevelIsLessThanOrEqualToSomething() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where level is less than or equal to DEFAULT_LEVEL
        defaultTemplateTypeShouldBeFound("level.lessThanOrEqual=" + DEFAULT_LEVEL);

        // Get all the templateTypeList where level is less than or equal to SMALLER_LEVEL
        defaultTemplateTypeShouldNotBeFound("level.lessThanOrEqual=" + SMALLER_LEVEL);
    }

    @Test
    @Transactional
    public void getAllTemplateTypesByLevelIsLessThanSomething() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where level is less than DEFAULT_LEVEL
        defaultTemplateTypeShouldNotBeFound("level.lessThan=" + DEFAULT_LEVEL);

        // Get all the templateTypeList where level is less than UPDATED_LEVEL
        defaultTemplateTypeShouldBeFound("level.lessThan=" + UPDATED_LEVEL);
    }

    @Test
    @Transactional
    public void getAllTemplateTypesByLevelIsGreaterThanSomething() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        // Get all the templateTypeList where level is greater than DEFAULT_LEVEL
        defaultTemplateTypeShouldNotBeFound("level.greaterThan=" + DEFAULT_LEVEL);

        // Get all the templateTypeList where level is greater than SMALLER_LEVEL
        defaultTemplateTypeShouldBeFound("level.greaterThan=" + SMALLER_LEVEL);
    }

    /**
     * Executes the search, and checks that the default entity is returned.
     */
    private void defaultTemplateTypeShouldBeFound(String filter) throws Exception {
        restTemplateTypeMockMvc.perform(get("/api/template-types?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(templateType.getId().intValue())))
            .andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME)))
            .andExpect(jsonPath("$.[*].pid").value(hasItem(DEFAULT_PID.intValue())))
            .andExpect(jsonPath("$.[*].code").value(hasItem(DEFAULT_CODE)))
            .andExpect(jsonPath("$.[*].rid").value(hasItem(DEFAULT_RID.intValue())))
            .andExpect(jsonPath("$.[*].enabled").value(hasItem(DEFAULT_ENABLED.booleanValue())))
            .andExpect(jsonPath("$.[*].level").value(hasItem(DEFAULT_LEVEL)));

        // Check, that the count call also returns 1
        restTemplateTypeMockMvc.perform(get("/api/template-types/count?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(content().string("1"));
    }

    /**
     * Executes the search, and checks that the default entity is not returned.
     */
    private void defaultTemplateTypeShouldNotBeFound(String filter) throws Exception {
        restTemplateTypeMockMvc.perform(get("/api/template-types?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$").isArray())
            .andExpect(jsonPath("$").isEmpty());

        // Check, that the count call also returns 0
        restTemplateTypeMockMvc.perform(get("/api/template-types/count?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(content().string("0"));
    }

    @Test
    @Transactional
    public void getNonExistingTemplateType() throws Exception {
        // Get the templateType
        restTemplateTypeMockMvc.perform(get("/api/template-types/{id}", Long.MAX_VALUE))
            .andExpect(status().isNotFound());
    }

    @Test
    @Transactional
    public void updateTemplateType() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        int databaseSizeBeforeUpdate = templateTypeRepository.findAll().size();

        // Update the templateType
        TemplateType updatedTemplateType = templateTypeRepository.findById(templateType.getId()).get();
        // Disconnect from session so that the updates on updatedTemplateType are not directly saved in db
        em.detach(updatedTemplateType);
        updatedTemplateType
            .name(UPDATED_NAME)
            .pid(UPDATED_PID)
            .code(UPDATED_CODE)
            .rid(UPDATED_RID)
            .enabled(UPDATED_ENABLED)
            .level(UPDATED_LEVEL);
        TemplateTypeDTO templateTypeDTO = templateTypeMapper.toDto(updatedTemplateType);

        restTemplateTypeMockMvc.perform(put("/api/template-types").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(templateTypeDTO)))
            .andExpect(status().isOk());

        // Validate the TemplateType in the database
        List<TemplateType> templateTypeList = templateTypeRepository.findAll();
        assertThat(templateTypeList).hasSize(databaseSizeBeforeUpdate);
        TemplateType testTemplateType = templateTypeList.get(templateTypeList.size() - 1);
        assertThat(testTemplateType.getName()).isEqualTo(UPDATED_NAME);
        assertThat(testTemplateType.getPid()).isEqualTo(UPDATED_PID);
        assertThat(testTemplateType.getCode()).isEqualTo(UPDATED_CODE);
        assertThat(testTemplateType.getRid()).isEqualTo(UPDATED_RID);
        assertThat(testTemplateType.isEnabled()).isEqualTo(UPDATED_ENABLED);
        assertThat(testTemplateType.getLevel()).isEqualTo(UPDATED_LEVEL);
    }

    @Test
    @Transactional
    public void updateNonExistingTemplateType() throws Exception {
        int databaseSizeBeforeUpdate = templateTypeRepository.findAll().size();

        // Create the TemplateType
        TemplateTypeDTO templateTypeDTO = templateTypeMapper.toDto(templateType);

        // If the entity doesn't have an ID, it will throw BadRequestAlertException
        restTemplateTypeMockMvc.perform(put("/api/template-types").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(templateTypeDTO)))
            .andExpect(status().isBadRequest());

        // Validate the TemplateType in the database
        List<TemplateType> templateTypeList = templateTypeRepository.findAll();
        assertThat(templateTypeList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    public void deleteTemplateType() throws Exception {
        // Initialize the database
        templateTypeRepository.saveAndFlush(templateType);

        int databaseSizeBeforeDelete = templateTypeRepository.findAll().size();

        // Delete the templateType
        restTemplateTypeMockMvc.perform(delete("/api/template-types/{id}", templateType.getId()).with(csrf())
            .accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isNoContent());

        // Validate the database contains one less item
        List<TemplateType> templateTypeList = templateTypeRepository.findAll();
        assertThat(templateTypeList).hasSize(databaseSizeBeforeDelete - 1);
    }
}
